/*
 * Copyright 2007 MBARI
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package org.mbari.vcr;

import java.io.IOException;
import org.mbari.comm.BadPortException;
import org.mbari.vcr.rs422.VCR;

/**
 * Class description
 *
 *
 * @version    $Id: $
 * @author     Brian Schlining
 */
public class VCRTestRxtx3 {

    private final RxtxVcr vcr;

    VCRTestRxtx3(String serialPortName) throws BadPortException, IOException {
        vcr = new RxtxVcr(serialPortName);
    }

    /**
     * Method description
     *
     *
     * @throws InterruptedException
     */
    public void runTest() throws InterruptedException {
        vcr.send(VCR.GET_STATUS);
        vcr.send(VCR.GET_TIMECODE);
        vcr.send(VCR.PLAY_FWD);
        vcr.send(VCR.GET_STATUS);
        vcr.send(VCR.GET_TIMECODE);
        Thread.sleep(2000);
        vcr.send(VCR.STOP);
        vcr.send(VCR.GET_TIMECODE);
        Thread.sleep(2000);
        vcr.send(VCR.GET_TIMECODE1);
        Thread.sleep(2000);
        vcr.send(VCR.GET_TIMECODE2);
        Thread.sleep(2000);
        vcr.send(VCR.GET_STATUS);
        Thread.sleep(2000);
        vcr.send(VCR.GET_TIMECODE);
        vcr.send(VCR.PLAY_FWD);
        vcr.send(VCR.GET_STATUS);
        vcr.send(VCR.GET_TIMECODE);
        Thread.sleep(2000);
        vcr.send(VCR.STOP);
        vcr.send(VCR.GET_TIMECODE);
        Thread.sleep(2000);
        vcr.send(VCR.GET_TIMECODE1);
        Thread.sleep(2000);
        vcr.send(VCR.GET_TIMECODE2);
        Thread.sleep(2000);
        vcr.send(VCR.GET_STATUS);
        Thread.sleep(2000);
        System.exit(0);
    }

    /**
     * Method description
     *
     *
     * @param args
     *
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        VCRTestRxtx3 test = new VCRTestRxtx3("COM2");
        test.runTest();
    }

    private class RxtxVcr extends VCR {

        /**
         * Constructs ...
         *
         *
         * @param serialPortName
         *
         * @throws BadPortException
         * @throws IOException
         */
        public RxtxVcr(String serialPortName) throws BadPortException, IOException {
            super(serialPortName);
        }

        void send(byte[] command) {
            sendCommand(command);
        }
    }
}
